package com.diana.springcloud.cloudconsumer.feign.impl;

import com.diana.springcloud.cloudconsumer.entity.UserEntity;
import com.diana.springcloud.cloudconsumer.feign.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

/**
 * @Author Suna
 * @Date 2020/8/24 16:44
 */
@Component
public class FeignFallbackFactory implements FallbackFactory<UserFeignClient> {

    private static final Log log = LogFactory.getLog(FeignFallbackFactory.class);

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public UserEntity getUser(int userId) {
                FeignFallbackFactory.log.info("fallback:reason was:"+throwable);
                UserEntity userEntity = new UserEntity();
                userEntity.setUserId(3);
                userEntity.setAge(0);
                userEntity.setName("默认用户");
                return userEntity;
            }
        };
    }
}
